﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HammerMUD.Characters;
using HammerMUD.System;
using HammerMUD.Items;
using HammerMUD.NPC;

namespace HammerMUD.Commands
{
    public class LookCommand : Command
    {
        public LookCommand()
        {
            Name = "look";
            Help =  "look at <object/character/npc>\n" +
                    "look <object/character/npc/direction>\n" +
                    "look in <object>";
            SecurityLevel = HammerMUD.Admin.SecurityLevel.User;
        }

        public override void Do(User from, List<string> arguments)
        {
            if (arguments.Count == 1)
            {
                String message = from.UserAccount.CurrentCharacter.CurrentRoom.Name + "\n\r";
                String newLine = String.Empty;
                Boolean isFirst = true;

                newLine = newLine + "You can see ";
                foreach(Character c in from.UserAccount.CurrentCharacter.CurrentRoom.Characters)
                {
                    if(isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        if(newLine.Length > 70)
                        {
                            newLine = newLine + ", \n\r";
                            message = message + newLine;
                            newLine = String.Empty;
                        }
                        else
                        {
                            newLine = newLine + ", ";
                        }
                    }
                    newLine = newLine + c.Name;
                }

                foreach (Npc n in from.UserAccount.CurrentCharacter.CurrentRoom.Npcs)
                {
                    if (isFirst)
                    {
                        isFirst = false;
                    }
                    else
                    {
                        if (newLine.Length > 70)
                        {
                            newLine = newLine + ", \n\r";
                            message = message + newLine;
                            newLine = String.Empty;
                        }
                        else
                        {
                            newLine = newLine + ", ";
                        }
                    }
                    newLine = newLine + n.Name;
                }
                message = message + newLine + " here.\n\r";

                if(from.UserAccount.CurrentCharacter.CurrentRoom.Items.Count > 0)
                {
                    isFirst = true;
                    newLine = String.Empty;
                    foreach (Item i in from.UserAccount.CurrentCharacter.CurrentRoom.Items)
                    {
                        if (isFirst)
                        {
                            isFirst = false;
                        }
                        else
                        {
                            if (newLine.Length > 70)
                            {
                                newLine = newLine + ", \n\r";
                                message = message + newLine;
                                newLine = String.Empty;
                            }
                            else
                            {
                                newLine = newLine + ", ";
                            }
                        }
                        newLine = newLine + i.Name;
                    }

                    if (from.UserAccount.CurrentCharacter.CurrentRoom.Items.Count > 1)
                    {
                        message = message + newLine + " are nearby";
                    }
                    else
                    {
                        message = message + newLine + " is nearby";
                    }
                }

                from.Send(message);
                return;
            }

            from.Send("Sorry. The rest of look is not yet implemented!");
        }

        public static void DoLook(User from)
        {
            LookCommand look = new LookCommand();
            List<String> arguments = new List<String>();
            arguments.Add("look");
            look.Do(from, arguments);
        }
    }
}
